/**
 * 
 */
package parsing;
import java.util.ArrayList;
import java.util.List;



public class Person {
	 
	//static members
	private static int counterID = 1;
	
	//private members
    private String name;
    private int ID; /*auto increment*/
    private List<Integer> categories;/* 1: sports players, 2: actors, 3: singers*/
    private String birthCity;
    private int birthCityID; /*by SQL*/
    private String deathCity;
    private int  deathCityID; /*by SQL*/

    //constructor
    public Person(String name) {
    	this.ID = counterID;
    	counterID++;
        this.name = name;
        this.categories = new ArrayList<Integer>();
        this.birthCity = this.deathCity = null;
    }
    
	//Different Constructor, For Simulation
    public Person(String name, int categoryID, int birthCityID, int deathCityID) {
    	this.ID = counterID;
    	counterID++;
        this.name = name;
        this.categories = new ArrayList<Integer>();
        addCategory(categoryID);
        this.birthCityID = birthCityID;
        this.deathCityID = deathCityID;
    }
    
    public Person(String name, int ID, int categoryID, int birthCityID, int deathCityID) {
    	this.ID = ID;
        this.name = name;
        this.categories = new ArrayList<Integer>();
        addCategory(categoryID);
        this.birthCityID = birthCityID;
        this.deathCityID = deathCityID;
    }
    
    public int getID() {
		return ID;
	}

	public void setID(int iD) {
		ID = iD;
	}

	public int getBirthCityID() {
		return birthCityID;
	}

	public void setBirthCityID(int birthCityID) {
		this.birthCityID = birthCityID;
	}

	public int getDeathCityID() {
		return deathCityID;
	}

	public void setDeathCityID(int deathCityID) {
		this.deathCityID = deathCityID;
	}

	public void setName(String name) {
		this.name = name;
	}

	public void setCategories(List<Integer> categories) {
		this.categories = categories;
	}


    //setters
    public void setBirthCity(String birthCity) {
        this.birthCity = birthCity;
    }

    public void setDeathCity(String deathCity) {
        this.deathCity = deathCity;
    }
    
    public void addCategory(int categoryID){
    	this.categories.add(categoryID);
    }

    //getters
    public String getName() {
        return name;
    }
    
    public int getId(){
    	return ID;
    }
   
    public String getBirthCity(){
    	return birthCity;
    }
    
    public String getDeathCity(){
    	return deathCity;
    }
    
    public List<Integer> getCategories(){
    	return categories;
    }
    
    
    public boolean isOnCategory(int categoryID){
    	return this.categories.contains(categoryID);
    }
    
    @Override 
    public String toString(){
    	StringBuffer bf = new StringBuffer(); 
    	bf.append("name: \t"+this.name+ "\n" 
				+ "categories: \t"+ this.categories.toString() + "\n");
    	if(this.birthCity != null){
    		bf.append("born in: \t" + this.birthCity + "\n");}
    	if (this.deathCity != null){
    		bf.append("died in: \t"+ this.deathCity + "\n");
    	}
		return bf.toString();

    	
    }

    //checks if death city is a known city and updates persons 
	public void identifyDeathCity() {
		
		// TODO Auto-generated method stub
		City currDeathCity = ParserCity.getCity(this.deathCity);
		if(currDeathCity != null ){
			this.deathCityID = currDeathCity.cityId;
			this.deathCity = currDeathCity.cityName;
		}
	}

	//checks if birth city is a known city and updates persons 
	public void identifyBirthCity() {
		City currBirthCity = ParserCity.getCity(this.birthCity);
		if(currBirthCity != null ){
			this.birthCityID = currBirthCity.cityId;
			this.birthCity = currBirthCity.cityName;
		}
		
	}
	

}
